package evolution.problem;

import static java.lang.Math.*;

public class Schaffer2DMinimization extends AbstractMinimizationProblem {

	public static final Problem2DConstraints CONSTRAINTS = new Problem2DConstraints(
			-100, 100);

	public Schaffer2DMinimization() {
		super(CONSTRAINTS);
	}

	/**
	 * http://www.math.ntu.edu.tw/~wwang/cola_lab/test_problems/multiple_opt/
	 * multiopt_prob/Schaffer%202/Schaffer%202.htm
	 */
	@Override
	public double getValue(double[] x) {
		double x1 = x[0];
		double x2 = x[1];

		double a = (x1 * x1 + x2 * x2);
		double left = pow(a, 0.25);
		double right = pow(sin(50 * (pow(a, 0.1))), 2) + 1;

		return left * right;
	}

	@Override
	public String getGnuplotFunction() {
		return "(x*x+y*y)**(0.25) * (sin(50 * ((x*x+y*y)**(0.1)))**2 + 1)";
	}

	@Override
	public String getGnuplotFunctionName() {
		return "schaffer_2";
	}
}
